1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4 using
UnityEditor;
5 using
System;
6 using
System.IO;
7 using
System.Reflection;
8
9 [CustomEditor(
typeof(Readme))]
10 [InitializeOnLoad]

11 public
class ReadmeEditor : Editor {
12     
13     
static string kShowedReadmeSessionStateName = "ReadmeEditor.showedReadme";
14     
15     
static float kSpace = 16f;
16     
17     
static ReadmeEditor()
18     {
19         EditorApplication.delayCall += SelectReadmeAutomatically;
20     }
21     
22     
static void SelectReadmeAutomatically()
23     {
24         
if (!SessionState.GetBool(kShowedReadmeSessionStateName, false ))
25         {
26             
var readme = SelectReadme();
27             SessionState.SetBool(kShowedReadmeSessionStateName,
true);
28             
29             
if (readme && !readme.loadedLayout)
30             {
31                 LoadLayout();
32                 readme.loadedLayout =
true;
33             }
34         }
35     }
36     
37     
static void LoadLayout()
38     {
39         
var assembly = typeof(EditorApplication).Assembly;
40         
var windowLayoutType = assembly.GetType("UnityEditor.WindowLayout", true);
41         
var method = windowLayoutType.GetMethod("LoadWindowLayout", BindingFlags.Public | BindingFlags.Static);
42         method.Invoke(
null, new object[]{Path.Combine(Application.dataPath, "TutorialInfo/Layout.wlt"), false});
43     }
44     
45     
[MenuItem("Tutorial/Show Tutorial Instructions")]
46     
static Readme SelectReadme()
47     {
48         
var ids = AssetDatabase.FindAssets("Readme t:Readme");
49         
if (ids.Length == 1)
50         {
51             
var readmeObject = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(ids[0]));
52             
53             Selection.objects =
new UnityEngine.Object[]{readmeObject};
54             
55             
return (Readme)readmeObject;
56         }
57         
else
58         {
59             Debug.Log(
"Couldn't find a readme");
60             
return null;
61         }
62     }
63     
64     
protected override void OnHeaderGUI()
65     {
66         
var readme = (Readme)target;
67         Init();
68         
69         
var iconWidth = Mathf.Min(EditorGUIUtility.currentViewWidth/3f - 20f, 128f);
70         
71         GUILayout.BeginHorizontal(
"In BigTitle");
72         {
73             GUILayout.Label(readme.icon, GUILayout.Width(iconWidth), GUILayout.Height(iconWidth));
74             GUILayout.Label(readme.title, TitleStyle);
75         }
76         GUILayout.EndHorizontal();
77     }
78     
79     
public override void OnInspectorGUI()
80     {
81         
var readme = (Readme)target;
82         Init();
83         
84         
foreach (var section in readme.sections)
85         {
86             
if (!string.IsNullOrEmpty(section.heading))
87             {
88                 GUILayout.Label(section.heading, HeadingStyle);
89             }
90             
if (!string.IsNullOrEmpty(section.text))
91             {
92                 GUILayout.Label(section.text, BodyStyle);
93             }
94             
if (!string.IsNullOrEmpty(section.linkText))
95             {
96                 
if (LinkLabel(new GUIContent(section.linkText)))
97                 {
98                     Application.OpenURL(section.url);
99                 }
100             }
101             GUILayout.Space(kSpace);
102         }
103     }
104     
105     
106     
bool m_Initialized;
107     
108     GUIStyle LinkStyle {
get { return m_LinkStyle; } }
109     [SerializeField] GUIStyle m_LinkStyle;
110     
111     GUIStyle TitleStyle {
get { return m_TitleStyle; } }
112     [SerializeField] GUIStyle m_TitleStyle;
113     
114     GUIStyle HeadingStyle {
get { return m_HeadingStyle; } }
115     [SerializeField] GUIStyle m_HeadingStyle;
116     
117     GUIStyle BodyStyle {
get { return m_BodyStyle; } }
118     [SerializeField] GUIStyle m_BodyStyle;
119     
120     
void Init()
121     {
122         
if (m_Initialized)
123             
return;
124         m_BodyStyle =
new GUIStyle(EditorStyles.label);
125         m_BodyStyle.wordWrap =
true;
126         m_BodyStyle.fontSize =
14;
127         
128         m_TitleStyle =
new GUIStyle(m_BodyStyle);
129         m_TitleStyle.fontSize =
26;
130         
131         m_HeadingStyle =
new GUIStyle(m_BodyStyle);
132         m_HeadingStyle.fontSize =
18 ;
133         
134         m_LinkStyle =
new GUIStyle(m_BodyStyle);
135         m_LinkStyle.wordWrap =
false;
136         
// Match selection color which works nicely for both light and dark skins
137         m_LinkStyle.normal.textColor =
new Color (0x00/255f, 0x78/255f, 0xDA/255f, 1f);
138         m_LinkStyle.stretchWidth =
false;
139         
140         m_Initialized =
true;
141     }
142     
143     
bool LinkLabel (GUIContent label, params GUILayoutOption[] options)
144     {
145         
var position = GUILayoutUtility.GetRect(label, LinkStyle, options);
146
147         Handles.BeginGUI ();
148         Handles.color = LinkStyle.normal.textColor;
149         Handles.DrawLine (
new Vector3(position.xMin, position.yMax), new Vector3(position.xMax, position.yMax));
150         Handles.color = Color.white;
151         Handles.EndGUI ();
152
153         EditorGUIUtility.AddCursorRect (position, MouseCursor.Link);
154
155         
return GUI.Button (position, label, LinkStyle);
156     }
157 }


Match selection color which works nicely for both light and dark skins




Trò chơi giống như Rogue 2D sử dụng Unity 28.451 lượt xem

Gõ tìm kiếm nhanh...